﻿using System.Collections.Generic;
using Model.DBInteractions;
using Model.EntityRepositories;
using Model.Entities;
using Model.Interfaces;

namespace Model.Services
{
    public class NewsService : INewsService
    {
         private readonly INewsRepository _NewsRepository;
        private readonly IUnitOfWork _unitOfWork;
        public NewsService(INewsRepository NewsRepository, IUnitOfWork unitOfWork)
        {
            this._NewsRepository = NewsRepository;
            this._unitOfWork = unitOfWork;
        }  
        #region INewsService Members

        public IEnumerable<News> GetNews()
        {
            var News = _NewsRepository.GetAll();
            return News;
        }

        public News GetNewsById(int id)
        {
            var News = _NewsRepository.GetById(id);
            return News;
        }

        public void CreateNews(News News)
        {
            _NewsRepository.Add(News);
            _unitOfWork.Commit();
        }

        public void DeleteNews(int id)
        {
            var News = _NewsRepository.GetById(id);
            _NewsRepository.Delete(News);
            _unitOfWork.Commit();
        }

        public void UpdateNews(News News)
        {
            _NewsRepository.Update(News);
            _unitOfWork.Commit();
        }

        public void SaveNews()
        {
            _unitOfWork.Commit();
        }

        #endregion
    }
}
